
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/30/2012 08:45:56
-- Generated from EDMX file: C:\Users\s.vigano\Codice\MyProjects\tar\TAR\TAR4_Model\Restaurant.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [toDelete];
GO
IF SCHEMA_ID(N'Restaurant') IS NULL EXECUTE(N'CREATE SCHEMA [Restaurant]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[Restaurant].[FK_ProductDeliverySite]', 'F') IS NOT NULL
    ALTER TABLE [Restaurant].[ProductSet] DROP CONSTRAINT [FK_ProductDeliverySite];
GO
IF OBJECT_ID(N'[Restaurant].[FK_MenuProductInStock]', 'F') IS NOT NULL
    ALTER TABLE [Restaurant].[ProductInStocks] DROP CONSTRAINT [FK_MenuProductInStock];
GO
IF OBJECT_ID(N'[Restaurant].[FK_ProductInStockProduct]', 'F') IS NOT NULL
    ALTER TABLE [Restaurant].[ProductInStocks] DROP CONSTRAINT [FK_ProductInStockProduct];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[Restaurant].[ProductSet]', 'U') IS NOT NULL
    DROP TABLE [Restaurant].[ProductSet];
GO
IF OBJECT_ID(N'[Restaurant].[DeliverySiteSet]', 'U') IS NOT NULL
    DROP TABLE [Restaurant].[DeliverySiteSet];
GO
IF OBJECT_ID(N'[Restaurant].[MenuSet]', 'U') IS NOT NULL
    DROP TABLE [Restaurant].[MenuSet];
GO
IF OBJECT_ID(N'[Restaurant].[ProductInStocks]', 'U') IS NOT NULL
    DROP TABLE [Restaurant].[ProductInStocks];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ProductSet'
CREATE TABLE [Restaurant].[ProductSet] (
    [Code] char(5)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ShortName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Buono] bit  NOT NULL,
    [DeliverySite_ID] int  NOT NULL
);
GO

-- Creating table 'DeliverySiteSet'
CREATE TABLE [Restaurant].[DeliverySiteSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MenuSet'
CREATE TABLE [Restaurant].[MenuSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [StartValidity] datetime  NOT NULL,
    [EndValidity] datetime  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProductInStocks'
CREATE TABLE [Restaurant].[ProductInStocks] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Menu_ID] int  NOT NULL,
    [Product_Code] char(5)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Code] in table 'ProductSet'
ALTER TABLE [Restaurant].[ProductSet]
ADD CONSTRAINT [PK_ProductSet]
    PRIMARY KEY CLUSTERED ([Code] ASC);
GO

-- Creating primary key on [ID] in table 'DeliverySiteSet'
ALTER TABLE [Restaurant].[DeliverySiteSet]
ADD CONSTRAINT [PK_DeliverySiteSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MenuSet'
ALTER TABLE [Restaurant].[MenuSet]
ADD CONSTRAINT [PK_MenuSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ProductInStocks'
ALTER TABLE [Restaurant].[ProductInStocks]
ADD CONSTRAINT [PK_ProductInStocks]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [DeliverySite_ID] in table 'ProductSet'
ALTER TABLE [Restaurant].[ProductSet]
ADD CONSTRAINT [FK_ProductDeliverySite]
    FOREIGN KEY ([DeliverySite_ID])
    REFERENCES [Restaurant].[DeliverySiteSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductDeliverySite'
CREATE INDEX [IX_FK_ProductDeliverySite]
ON [Restaurant].[ProductSet]
    ([DeliverySite_ID]);
GO

-- Creating foreign key on [Menu_ID] in table 'ProductInStocks'
ALTER TABLE [Restaurant].[ProductInStocks]
ADD CONSTRAINT [FK_MenuProductInStock]
    FOREIGN KEY ([Menu_ID])
    REFERENCES [Restaurant].[MenuSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MenuProductInStock'
CREATE INDEX [IX_FK_MenuProductInStock]
ON [Restaurant].[ProductInStocks]
    ([Menu_ID]);
GO

-- Creating foreign key on [Product_Code] in table 'ProductInStocks'
ALTER TABLE [Restaurant].[ProductInStocks]
ADD CONSTRAINT [FK_ProductInStockProduct]
    FOREIGN KEY ([Product_Code])
    REFERENCES [Restaurant].[ProductSet]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductInStockProduct'
CREATE INDEX [IX_FK_ProductInStockProduct]
ON [Restaurant].[ProductInStocks]
    ([Product_Code]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------